package com.wjx.zk

import org.apache.curator.framework.recipes.locks.InterProcessMutex
import java.time.LocalDateTime
import java.util.concurrent.CountDownLatch

class Lock {
}

fun main(args: Array<String>) {
    val zk = getInstance()
    val lockPath = "/lock"
    val lock = InterProcessMutex(zk, lockPath)
    val down = CountDownLatch(1)
    for (i in 0..30) {
        Thread(Runnable {
            run {
                down.await()
                lock.acquire()
                println(Thread.currentThread().toString() + LocalDateTime.now())
                lock.release()
            }
        }).start()
    }
    down.countDown()
}